///////////////////////////////////////////////////////////////////////////////
////  (c) Chaichuk AU (chaichuk@mail.ru), 								   ////
////  2005, Chelyabinsk, NTC Privodnaya Tehnika (momentum@chel.surnet.ru)  ////
///////////////////////////////////////////////////////////////////////////////

#ifndef __ANYBUS_PCI_H_
#define __ANYBUS_PCI_H_

#include <pthread.h>
#include <sys/iofunc.h>
#include "anybus.h"


#define ANYBUS_DPM_VENDOR_ID	0x10b5
#define ANYBUS_DPM_DEVICE_ID	0x2889

//PLX interrupt register
#define PLX_INTR_REG			0x4C

//PLX interrupt flags
#define LINT1_ENABLE			(1<<0)
#define LINT1_HIGH				(1<<1)
#define LINT1_ACTIVE			(1<<2)

#define LINT2_ENABLE			(1<<3)
#define LINT2_HIGH				(1<<4)
#define LINT2_ACTIVE			(1<<5)

#define PCI_INTR_ENABLE 		(1<<6)
#define SOFT_INTR				(1<<7)

#define LINT1_EDGE				(1<<8)
#define LINT2_EDGE				(1<<9)

#define LINT1_ACK				(1<<10)
#define LINT2_ACK				(1<<11)


typedef struct abs_pci_board_s {
	
	abs_module_t		abs_module;

	uint64_t			mem_addr;
	uint32_t			io_addr;
	
	uintptr_t			iobase;
	uint8_t*			mem_ptr;
	
	uint32_t			irq;
	uint32_t			pci_index;
	uchar_t				mode;
	
	int					chid;			// channel id
	int					coid;			// connection id
	pthread_t			tid;			// thread id
	int					iid;			// interrupt id

	pthread_mutex_t		mutex;

//	intrspin_t			lock;
//	pthread_mutex_t		cond_mutex;
//	pthread_cond_t		cond;
//	int					cond_rcv;


} abs_pci_board_t;

typedef struct abs_dpm_attr_s {
	iofunc_attr_t	attr;
	abs_pci_board_t	board;
} abs_dpm_attr_t;


int abs_pci_init_board (abs_pci_board_t* board, int pci_index);


#endif // __ANYBUS_PCI_H_
